import sqlite3


class SqlLiteClient:
    def __init__(self, db_path):
        self.db_path = db_path

    def execute_sql(self, sql):
        conn = sqlite3.connect(self.db_path)
        cursor = conn.cursor()
        cursor.execute(sql)
        headers = [description[0] for description in cursor.description]
        rows = cursor.fetchall()
        cursor.close()
        result = []
        for row in rows:
            elements = {}
            for index, header in enumerate(headers):
                elements[header] = row[index]
            result.append(elements)
        return result


if __name__ == "__main__":
    sql_client = SqlLiteClient()
    sql = """select income as "收入"
    from kpi_data
    where year in (2024) and month in (11) and province in ('北京') and product_lv1 in ('产互KPI') 
    order by income desc
    """
    res = sql_client.execute_sql(sql)
    print(res)
